package com.google.android.gms.internal;

import com.google.android.gms.internal.zzdwg;
import java.security.GeneralSecurityException;
import javax.crypto.spec.SecretKeySpec;

final class zzdui implements zzdtf<zzdtj> {
    zzdui() {
    }

    private static void zza(zzdwe zzdwe) throws GeneralSecurityException {
        if (zzdwe.zzbqr() < 10) {
            throw new GeneralSecurityException("tag size too small");
        }
        switch (zzduj.zzmfk[zzdwe.zzbqq().ordinal()]) {
            case 1:
                if (zzdwe.zzbqr() > 20) {
                    throw new GeneralSecurityException("tag size too big");
                }
                return;
            case 2:
                if (zzdwe.zzbqr() > 32) {
                    throw new GeneralSecurityException("tag size too big");
                }
                return;
            case 3:
                if (zzdwe.zzbqr() > 64) {
                    throw new GeneralSecurityException("tag size too big");
                }
                return;
            default:
                throw new GeneralSecurityException("unknown hash type");
        }
    }

    /* access modifiers changed from: private */
    /* renamed from: zzh */
    public final zzdtj zza(zzfgs zzfgs) throws GeneralSecurityException {
        zzdyj zzdyj;
        try {
            zzdwa zzae = zzdwa.zzae(zzfgs);
            if (!(zzae instanceof zzdwa)) {
                throw new GeneralSecurityException("expected HmacKey proto");
            }
            zzdwa zzdwa = zzae;
            zzdyp.zzw(zzdwa.getVersion(), 0);
            if (zzdwa.zzbot().size() < 16) {
                throw new GeneralSecurityException("key too short");
            }
            zza(zzdwa.zzbqk());
            zzdvy zzbqq = zzdwa.zzbqk().zzbqq();
            SecretKeySpec secretKeySpec = new SecretKeySpec(zzdwa.zzbot().toByteArray(), "HMAC");
            int zzbqr = zzdwa.zzbqk().zzbqr();
            switch (zzduj.zzmfk[zzbqq.ordinal()]) {
                case 1:
                    zzdyj = new zzdyj("HMACSHA1", secretKeySpec, zzbqr);
                    break;
                case 2:
                    zzdyj = new zzdyj("HMACSHA256", secretKeySpec, zzbqr);
                    break;
                case 3:
                    zzdyj = new zzdyj("HMACSHA512", secretKeySpec, zzbqr);
                    break;
                default:
                    throw new GeneralSecurityException("unknown hash");
            }
            return zzdyj;
        } catch (zzfie e) {
            throw new GeneralSecurityException("expected serialized HmacKey proto", e);
        }
    }

    public final int getVersion() {
        return 0;
    }

    public final /* synthetic */ Object zza(zzfjc zzfjc) throws GeneralSecurityException {
        if (!(zzfjc instanceof zzdwa)) {
            throw new GeneralSecurityException("expected HmacKey proto");
        }
        zzdwa zzdwa = (zzdwa) zzfjc;
        zzdyp.zzw(zzdwa.getVersion(), 0);
        if (zzdwa.zzbot().size() < 16) {
            throw new GeneralSecurityException("key too short");
        }
        zza(zzdwa.zzbqk());
        zzdvy zzbqq = zzdwa.zzbqk().zzbqq();
        SecretKeySpec secretKeySpec = new SecretKeySpec(zzdwa.zzbot().toByteArray(), "HMAC");
        int zzbqr = zzdwa.zzbqk().zzbqr();
        switch (zzduj.zzmfk[zzbqq.ordinal()]) {
            case 1:
                return new zzdyj("HMACSHA1", secretKeySpec, zzbqr);
            case 2:
                return new zzdyj("HMACSHA256", secretKeySpec, zzbqr);
            case 3:
                return new zzdyj("HMACSHA512", secretKeySpec, zzbqr);
            default:
                throw new GeneralSecurityException("unknown hash");
        }
    }

    public final zzfjc zzb(zzfgs zzfgs) throws GeneralSecurityException {
        try {
            return zzb((zzfjc) zzdwc.zzag(zzfgs));
        } catch (zzfie e) {
            throw new GeneralSecurityException("expected serialized HmacKeyFormat proto", e);
        }
    }

    public final zzfjc zzb(zzfjc zzfjc) throws GeneralSecurityException {
        if (!(zzfjc instanceof zzdwc)) {
            throw new GeneralSecurityException("expected HmacKeyFormat proto");
        }
        zzdwc zzdwc = (zzdwc) zzfjc;
        if (zzdwc.getKeySize() < 16) {
            throw new GeneralSecurityException("key too short");
        }
        zza(zzdwc.zzbqk());
        return zzdwa.zzbql().zzgm(0).zzc(zzdwc.zzbqk()).zzaf(zzfgs.zzaz(zzdyl.zzgy(zzdwc.getKeySize()))).zzczx();
    }

    public final zzdwg zzc(zzfgs zzfgs) throws GeneralSecurityException {
        return (zzdwg) zzdwg.zzbqx().zzop("type.googleapis.com/google.crypto.tink.HmacKey").zzai(((zzdwa) zzb(zzfgs)).toByteString()).zzb(zzdwg.zzb.SYMMETRIC).zzczx();
    }
}
